﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;

namespace Gollie.Controls
{
	public partial class PercentageBar : System.Web.UI.UserControl
	{
		private uint value = 0;
		private uint maxValue = 100;
		private Color backColor = Color.White;
		private Color fillColor = Color.Gray;
		private int fullWidth = 180;
		private int stars = 1;

		protected void Page_Load(object sender, EventArgs e)
		{
			this.pnlBar.BackColor = backColor;
			this.pnlFiller.BackColor = fillColor;
			this.pnlBar.Width = fullWidth;

			if (this.MaxValue == 0) // no reviews?
			{
				this.pnlFiller.Width = 0;
			}
			else
			{
				if (this.value > this.MaxValue)
					throw new ArgumentException("PercentageBar: Value larger than max value");

				double ratio = (double)this.value / (double)this.MaxValue;

				this.pnlFiller.Width = Convert.ToInt32(Math.Round(ratio * this.FullWidth, 0));
			}

			this.lblValue.Text = this.value.ToString();

			this.lblStars.Text = this.stars.ToString();
		}

		public uint Value
		{
			get {return this.value;}

			set { this.value = value; }
		}

		public Color BarColor { get { return this.backColor; } set { this.backColor = value; } }
		public Color FillerColor { get { return this.fillColor; } set { this.fillColor = value; } }
		public int FullWidth { get { return this.fullWidth; } set { this.fullWidth = value; } }
		public uint MaxValue { get { return this.maxValue; } set { this.maxValue = value; } }
		public int Stars { get { return this.stars; } set { this.stars = value; } }
	}
}